package com.devops.admin.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devops.admin.mapper.DOSHelmChartUserRelationMapper;
import com.devops.admin.model.DOSHelmChartUserRelation;
import com.devops.admin.po.DOSChartUserVo;
import com.devops.admin.service.DOSHelmChartUserRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassNem DOSHelmChartUserRelationServiceImpl
 * @Description TODO
 * @Author heyabo
 * @Date 2022/3/23 15:21
 * @Version 1.0
 **/
@Service
public class DOSHelmChartUserRelationServiceImpl extends ServiceImpl<DOSHelmChartUserRelationMapper, DOSHelmChartUserRelation> implements DOSHelmChartUserRelationService {

    @Override
    public boolean distributionUser(DOSHelmChartUserRelation relation) {
        LambdaQueryWrapper<DOSHelmChartUserRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DOSHelmChartUserRelation::getUserId,relation.getUserId())
                .eq(DOSHelmChartUserRelation::getChartId,relation.getChartId());
        long count  = this.count(queryWrapper);
        Assert.isTrue(count<1,"不可重复绑定人员");

        return this.save(relation);
    }

    @Override
    public List<DOSChartUserVo> getUserList(Integer chartId) {
        return baseMapper.getUserList(chartId);
    }
}
